import {
  Body,
  Controller,
  Delete,
  Get,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { InstrumentService } from './instrument.service';
import { ListQueryDto } from './dto/list-query.dto';
import { SaveManagerDto } from './dto/saveManager.dto';
import { CreateInstrumentDto } from './dto/createInstrument.dto';
import { UpdateInstrumentDto } from './dto/updateInstrument.dto';
import { InstrumentMaintenanceDTO } from './dto/instrumentMaintenanc.dto';

@Controller('instrument')
export class InstrumentController {
  constructor(private readonly instrumentService: InstrumentService) {}

  @Get('list')
  async getList(@Query() query: ListQueryDto) {
    return await this.instrumentService.getList(query);
  }

  @Get('info')
  async getInstrumentInfo(@Query('id') id: string) {
    return await this.instrumentService.getInstrumentInfo(+id);
  }

  @Patch('saveManager')
  async saveManager(
    @Query('id') id: string,
    @Body() { managerId }: SaveManagerDto,
  ) {
    return await this.instrumentService.saveManager(+id, managerId);
  }

  @Post('add')
  async createInstrument(@Body() body: CreateInstrumentDto) {
    return await this.instrumentService.createInstrument(body);
  }

  @Patch('update')
  async updateInstrument(
    @Query('id') id: string,
    @Body() body: UpdateInstrumentDto,
  ) {
    return await this.instrumentService.updateInstrument(+id, body);
  }

  @Delete('delete')
  async deleteInstrument(@Query('id') id: string) {
    return await this.instrumentService.deleteInstrument(+id);
  }

  @Post('maintenance')
  async maintenanceInstrument(@Body() body: InstrumentMaintenanceDTO) {
    return await this.instrumentService.maintenanceInstrument(body);
  }
}
